from django.shortcuts import render
from django.views.generic import View
# Create your views here.
from user_info.models import *
from django.http import *


class Register(View):
    def get(self, request, *args, **kwargs, ):
        name = self.request.GET.get('name')
        password = self.request.GET.get('password')

        if name and password:
            user = User.objects.filter(name=name)
            if not user:
                user = User()
                user.name = name
                user.password = password
                user.save()
                return JsonResponse({"status_num": 0, 'massage': 'ok!!'})
            else:
                return JsonResponse(
                    {'status_num': 1, 'massage': 'error,user has already exists,please use others username!'})

        else:
            return JsonResponse({"status_num": 1, 'massage': 'error'})
